package com.markerhub.controller;
import com.markerhub.entity.Statics;
import com.markerhub.repository.StaitcsRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/statics")
public class StaticsHandler {
    @Autowired
    private StaitcsRepository staitcsRepository;
    @GetMapping("/findAll/{page}/{size}")
    public Page<Statics> findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        PageRequest request = PageRequest.of(page - 1, size);
        return staitcsRepository.findAll(request);
    }

    @PostMapping("/save")
    public String save(@RequestBody Statics statics) {
        Statics result = staitcsRepository.save(statics);
        if (result != null) {
            return "success";
        } else {
            return "error";
        }
    }

}
